//
//  GTMeSegment.m
//  GiftTalk
//
//  Created by Wan on 16/4/19.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTMeSegment.h"

@interface GTMeSegment ()

@property (weak, nonatomic) IBOutlet UIButton *descriptionButton;
@property (weak, nonatomic) IBOutlet UIButton *commentButton;
@property (weak, nonatomic) IBOutlet UIView *indicatorView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *indicatorViewLeftConstraint;

- (IBAction)descriptionButtonClick:(UIButton *)sender;
- (IBAction)commentButtonClick:(UIButton *)sender;

@end

@implementation GTMeSegment

- (void)awakeFromNib
{
    self.descriptionButton.layer.borderColor = GTRGBColor(220, 220, 220).CGColor;
    self.commentButton.layer.borderColor = GTRGBColor(220, 220, 220).CGColor;
    self.descriptionButton.layer.borderWidth = 0.5;
    self.commentButton.layer.borderWidth = 0.5;
    self.autoresizingMask = UIViewAutoresizingNone;
}

+ (instancetype)segment
{
    return [self viewFromXib];
}

#pragma mark - 监听点击事件
- (void)descriptionButtonAddTarget:(id)target selector:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    [self.descriptionButton addTarget:target action:action forControlEvents:controlEvents];
}

- (void)commentButtonClickAddTarget:(id)target selector:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    [self.commentButton addTarget:target action:action forControlEvents:controlEvents];
}

- (IBAction)descriptionButtonClick:(UIButton *)sender {
    [self setLeftConstraint: 0];
}

- (IBAction)commentButtonClick:(UIButton *)sender {
    [self setLeftConstraint:sender.width];
}

- (void)setLeftConstraint:(CGFloat)width {
    self.indicatorViewLeftConstraint.constant = width;
    
    [UIView animateWithDuration:0.25 animations:^{
        [self.indicatorView layoutIfNeeded];
    }];
}

@end
